<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Estadisticas
 *
 * @author marcelo.diaz
 */
class Estadisticas extends Controller{
    function Estadisticas(){
      parent::Controller();
    }

    function get_stats(){
      $evt = file_get_contents(base_url().'events.xml');
      $xml = new SimpleXMLElement($evt);
      $statistics = array();
      $can_events = 0;
      foreach($xml->marker as $hijo){
          $can_events ++;
          $name = str_replace(' ', '-', $hijo->add);

          if(key_exists($name, $statistics)){
              $statistics[$name] += 1;
          }else{
              $statistics[$name] = 1;
          }
      }
      //update stats
      foreach ($statistics as $k=>$v){
        $statistics[$k] = $v/$can_events;
      }

      $data = json_encode($statistics);
      //mail("conocepunta@gmail.com", "[acces-debug]", $marker->asXML());
      header('Content-Type:text/html');
      echo $data;
    }
}
?>
